import "../lib/node_modules/jquery/dist/jquery.min.js";
import "../config/base.js";
; (function ($) {
    "use strict"
    var _global;
    var Ajax = function (opt) {
        return new T(opt);
    }
    class T {
        constructor(opt) {
            opt && (this.url = opt.url || "");
            this.baseConfig = new BaseConfig();
        }
        post({type, url, data, beforeCallback, successCallback, errorCallback, completeCallback}) {
            let baseUrl="";
            switch (type) {  
                case "POST":
                    baseUrl = this.baseConfig.url;  
                  break;  
                case "GET":  
                    baseUrl = this.baseConfig.url;  
                  break;  
                default:  
                  break;  
              }
            $.ajax({
                url: baseUrl+(url || this.url),
                method: type,
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                beforeSend: function(){  
                    beforeCallback && beforeCallback();          
                }
            }).done(function (response) {
                console.log("请求成功:", response);
                successCallback && successCallback(response);
            }).fail(function (jqXHR) {
                console.log("请求失败:", jqXHR);
                errorCallback && errorCallback(jqXHR.responseJSON);
            }).always(function () {
                console.log("请求完成");
                completeCallback && completeCallback();
            });
        }
    }

    //将插件对象暴露给全局对象
    _global = (function () { return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = Ajax;
    } else if (typeof define === "function" && define.amd) {
        define(function () { return Ajax; });
    } else {
        !('Ajax' in _global) && (_global.Ajax = Ajax);
    }
})(jQuery);
